/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年9月8日 下午3:14:15
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.ssm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniu.ssm.domain.Blog;
import com.woniu.ssm.service.BlogService;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("blog")
public class BlogController {
	@Autowired
	BlogService bs;
	@RequestMapping("list")
	@ResponseBody
	public List<Blog> list(){
		return bs.selectListBlog();
	}
	@RequestMapping("single")
	@ResponseBody
	public Blog singleBlog(int id) {
		return bs.selectBlog(id);
	}
	@RequestMapping("add")
	@ResponseBody
	public String addBlog(@RequestBody Blog blog) {
		try {
			bs.addBlog(blog);
			return "1";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "0";
		}
		
	}
	@RequestMapping(value="del/{id}")
	@ResponseBody
	public String delBlog(@PathVariable int id) {
		try {
			//int bid = Integer.parseInt(id);
			bs.delBlog(id);
			return "1";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "0";
		}
	}
	@RequestMapping("update")
	@ResponseBody
	public String updateBlog(@RequestBody Blog blog) {
		try {
			bs.updateBlog(blog);
			return "1";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "0";
		}
		
	}
}
